package com.AAL.DAO;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.ITypeOfReportDAO;
import com.AAL.Model.TypesOfReport;
import com.AAL.Utils.HibernateUtil;

public class TypeOfReportDAO implements ITypeOfReportDAO{

	@SuppressWarnings("unchecked")
	@Override
	public List<TypesOfReport> getAllTypesOfReports() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<TypesOfReport> lstTypesOfReports = null;
		try {
			lstTypesOfReports = (List<TypesOfReport>) session.createQuery(
					"from TypesOfReport").list();
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return lstTypesOfReports;
	}

	@Override
	public TypesOfReport getTypesOfReport(int typeID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		TypesOfReport typesOfReport = (TypesOfReport) session.load(TypesOfReport.class, typeID);
		return typesOfReport;
	}

}
